<template>
	<view class="page company">
		<form>
			<view class="cu-form-group">
				<view class="title">企业名称</view>
				<input placeholder="请输入公司名称" @blur="handleBlur" v-model="formData.name"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">统一社会信用代码</view>
				<input placeholder="请输入公司编码" v-model="formData.code"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">实际经营地址</view>
				<input placeholder="请输入门牌地址" v-model="formData.house_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">注册地址</view>
				<input placeholder="请输入注册地址" v-model="formData.registered_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">所属街道</view>
				<input placeholder="请输入所属街道" v-model="formData.registered_address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">入驻类型</view>
				<input placeholder="请输入入驻类型" v-model="formData.type"></input>
			</view>

			<view class="cu-form-group">
				<view class="title">租用楼层</view>
				<input placeholder="请输入租用楼层"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">租用房间号</view>
				<input placeholder="请输入租用房间号"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">租用面积</view>
				<input placeholder="请输入租用面积"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">法定代表人姓名</view>
				<input placeholder="请输入法定代表人姓名" v-model="formData.legal_person"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">联系手机</view>
				<input placeholder="请输入联系手机" type="number" v-model="formData.legal_person_mobile"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">法人证件类型</view>
				<view class="uni-list-cell-db">
					<picker @change="bindPickerChange" :value="formData.legal_person_certificate_type - 1"
						:range="array">
						<view class="uni-input">{{array[formData.legal_person_certificate_type - 1]}}</view>
					</picker>
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">证件号码</view>
				<input placeholder="请输入证件号码" type="number" v-model="formData.legal_person_certificate_code"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">企业联络人姓名</view>
				<input placeholder="请输入企业联络人姓名"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">联系手机</view>
				<input placeholder="请输入联系手机"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">身份证</view>
				<input placeholder="请输入身份证"></input>
			</view>
			<view class="cu-form-group-top">
				<view class="title">省市区</view>
				<QnSelect @change="handleCardAddress" ></QnSelect>
			</view>
			<view class="cu-form-group">
				<view class="title">详细地址</view>
				<input placeholder="请输入详细地址"></input>
			</view>
			<view class="padding">
				<button @click="createEnterpriseFun" class="cu-btn block bg-blue margin-tb-sm lg">
					创建企业
				</button>
			</view>
		</form>
	</view>
</template>

<script>
	import getUrlParams from '@/utils/getUrlParams.js';
	import Autocomplete from '@/components/autocomplete';
	import {
		createEnterprise
	} from '../../api/enterprise.js'
	export default {
		components: {
			Autocomplete
		},
		data() {
			return {
				formData: {
					building_id: '',
					region_id: '',
					name: "",
					code: "",
					house_address: "",
					is_registered: 1,
					registered_address_status: 1,
					registered_address: "",
					people_number: "",
					type: "",
					industry: "",
					industry_label: "",
					business_scope: "",
					registration_authority: "",
					approve_time: null,
					head_office: 1,
					business_license: "",
					legal_person: null,
					legal_person_mobile: null,
					legal_person_certificate_type: 1,
					legal_person_certificate_code: null,
					legal_person_status: 1,
					legal_person_nationality: null,
				},
				array: ['身份证', '护照', '驾照']
			}
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo;
			},
			isLogin() {
				if (this.$store.state.token) {
					return true;
				} else {
					return false;
				}
			},
		},
		onLoad(query) {
			console.log("参数", query)
			if (this.isLogin) {
				if (query && query.q) {
					let data = getUrlParams(decodeURIComponent(query.q));
					this.formData['building_id'] = data.building_id;
					this.formData['region_id'] = data.region_id;
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			} else {
				this.$route("pages/login/login")
			}
		},
		methods: {
			handleCardAddress(res) {
				console.log('获取参数', res);
				this.formData.live_province = res.province;
				this.formData.live_city = res.city;
				this.formData.live_area = res.area;
				this.formData.live_street = res.street;
				this.formData.live_province_name = res.provinceName;
				this.formData.live_city_name = res.cityName;
				this.formData.live_area_name = res.areaName;
				this.formData.live_street_name = res.streetName;
			},
			/**
			 * 处理失焦
			 */
			handleBlur() {

			},
			/**
			 * @param {Object} bool
			 * @param {Object} key
			 */
			isSelected(bool, key) {
				this.formData[key] = bool
			},
			bindPickerChange(e) {
				this.formData.legal_person_certificate_type = Number(e.detail.value) + 1
			},
			createEnterpriseFun() {
				createEnterprise(this.formData).then(res => {
					console.log(res)
					uni.showToast({
						title: '认证成功',
						duration: 2000
					});
					uni.switchTab({
						url: '/pages/my/my'
					})
				})
			}
		}
	}
</script>

<style>

</style>
